<?php
/**
 * Created by PhpStorm.
 * User: 曹旺
 * Date: 2018-04-20
 * Time: 13:45
 */
namespace app\index\model;
use think\Db;
use think\Model;

class OrderCommodity extends Model{
    public function commodity_sale_number($id){
        $commodity_num=Db::table('nbsm_order_commodity')->field('commodity_id,number')->where(['order_id'=>$id])->select();
        foreach ($commodity_num as $key=>$value){
            $num=Db::table('nbsm_commodity')->field('commodity_sale_number')->where(['id'=>$value['commodity_id']])->find();
            $number=$num['commodity_sale_number']+$value['number'];
            Db::table('nbsm_commodity')->where(['id'=>$value['commodity_id']])->update(['commodity_sale_number'=>$number]);
        }
        return true;
    }
}